package response

import "github.com/gin-gonic/gin"

const (
	success = 200
	fail    = 500
)

func display(c *gin.Context, code int64, message string, data interface{}) {
	c.JSONP(200, gin.H{
		"code":    code,
		"message": message,
		"data":    data,
	})
	c.Abort()
}

func Success(c *gin.Context) {
	display(c, success, "操作成功", nil)
}

func SuccessWithData(c *gin.Context, data interface{}) {
	display(c, success, "操作成功", data)
}

func Fail(c *gin.Context, message string) {
	display(c, fail, message, nil)
}
